//==========窗口大小===========//
var size;
// 获取窗体大小
$(function(){
	var wHeight = $(window).height();
	var wWidth = $(window).width();
	size = {width : wWidth, height : wHeight};
});

//列表列宽比列计算
function fixWidth(percent) {
	return Math.round((Number(size.width)) * percent);
}

//刷新列表
function reloadList(listId){
	if(!listId){
		listId = "list";
	}
	$('#'+listId).datagrid("clearSelections");	//清空选择
	$('#'+listId).datagrid('reload');	//刷新列表
}

//日期框格式
function dateTimes(dateFmt) {
	if(!dateFmt){
		dateFmt = 'yyyy-MM-dd';
	}
	WdatePicker({
		dateFmt : dateFmt,
		isShowToday : true
	});
}

//弹出窗口
function openwindow(url,name,Width,Height) {
	var iTop = 90; // 获得窗口的垂直位置;
	var iLeft = 100; // 获得窗口的水平位置;
	window.open(url,name,'height='+Height+',,innerHeight='+Height+',width='+Width+',innerWidth='+Width+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}

//弹出窗口
function openModalDialog(url,name,Width,Height) {
	var returnValue = null;
	if (isIE()) {
		returnValue = window.showModalDialog(url,null,"dialogWidth:" + Width + "px;dialogHeight:" + Height + "px;center:yes;status:no;location=no;scroll:yes;help:no;");
	} else {
		alert("请使用标准IE浏览器。");
	}
	return returnValue;
}

//文本长度限制
function textAreaLength(field, maxlimit) {
	if(field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	}
}

//判断是否IE浏览器
function isIE(){
	return (navigator.userAgent.indexOf("MSIE")>0 || navigator.userAgent.indexOf("NET")>0);
}

//比较时间a，b大小。a>=b 返回true
function comptime(a,b) {
	//var a = "2009-09-21 00:00:01";
	//var b = "2009-09-21 00:00:00";
	var beginTimes = a.split('-');
	var endTimes = b.split('-');

	beginTime = beginTimes[1] + '-' + beginTimes[2] + '-' + beginTimes[0];
	endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0];
	
	var a = (Date.parse(endTime) - Date.parse(beginTime)) / 3600 / 1000;
	if (a <= 0) {
		return true;
	} else {
		return false;
	}
}

//初始化列表分页
function initListPage(listName){
	if(!listName){
		listName = "list";
	}
	$('#'+listName).datagrid('getPager').pagination({
		pageSize : 20,
		showPageList : false,
		pageList : [ 20 ],
		beforePageText : '第',//页数文本框前显示的汉字
		afterPageText : '页    共{pages}页',
		displayMsg : '当前显示 {from} - {to} 条记录    共{total}条记录'
	});
}

//单选框-重新加载
function mult_Call(id) {
	if(id){
		id = "#"+id;
	}else{
		id = ".mult";
	}
    $(id).multiselect({
       multiple:false,
       selectedList: 1
    });
};

//多选框-重新加载
function multiselect_Call(id) {
	if(id){
		id = "#"+id;
	}else{
		id = ".multiselect";
	}
    $(id).multiselect({
         multiselect:false
    });
};

//+---------------------------------------------------  
//| 求两个时间的天数差 日期格式为 YYYY-MM-dd   
//+---------------------------------------------------  
function daysBetween(DateOne,DateTwo)  
{   
  var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-'));  
  var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-')+1);  
  var OneYear = DateOne.substring(0,DateOne.indexOf ('-'));  

  var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ('-'));  
  var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ('-')+1);  
  var TwoYear = DateTwo.substring(0,DateTwo.indexOf ('-'));  

  var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);   
  return cha;  
} 

//获取当前时间 格式“yyyy-MM-dd HH:MM:SS”
function getNowFormatDate() {
	var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    return currentdate;
}

